package com.zhugang.week06;

import java.util.List;

/**
 * @program algorithms
 * @description: maxDepthN
 * @author: chanzhugang
 * @create: 2022/07/16 22:47
 */
public class MaxDepthN {

    /**
     * 559 N叉树的最大深度
     *
     * @param root
     * @return
     */
    public int maxDepthN(Node root) {
        if (root == null) {
            return 0;
        }
        int children = 0;
        for (int i = 0; i < root.children.size(); i++) {
            int maxDepth = maxDepthN(root.children.get(i));
            if (maxDepth > children) {
                children = maxDepth;
            }
        }
        return children + 1;
    }

    class Node {
        public int val;
        public List<Node> children;

        public Node() {
        }

        public Node(int _val) {
            val = _val;
        }

        public Node(int _val, List<Node> _children) {
            val = _val;
            children = _children;
        }
    }
}